package com.aaa.stock.service.impl;

import com.aaa.entity.StockProducer;
import com.aaa.entity.StockProvider;
import com.aaa.stock.dao.ProducerDao;
import com.aaa.stock.dao.ProviderDao;
import com.aaa.stock.service.ProducerService;
import com.aaa.stock.service.ProviderService;
import com.aaa.stock.vo.ProducerVo;
import com.aaa.stock.vo.ProviderVo;
import com.aaa.util.JwtUtil;
import com.aaa.util.WebUtil;
import com.aaa.vo.Result;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class ProviderServiceImpl extends ServiceImpl<ProviderDao, StockProvider> implements ProviderService {
    @Autowired
    private ProviderDao providerDao;



    @Override
    public Result<IPage<StockProvider>> getByPage(Integer currentPage, Integer pageSize, ProviderVo providerVo) {
        IPage<StockProvider>page=new Page<>(currentPage,pageSize);
        QueryWrapper<StockProvider>wrapper=new QueryWrapper<>();
        if (StringUtils.hasText(providerVo.getProviderName())){
            wrapper.like("provider_name",providerVo.getProviderName());
        }
        if (StringUtils.hasText(providerVo.getContactName())){
            wrapper.like("contact_name",providerVo.getContactName());
        }
        if (StringUtils.hasText(providerVo.getContactTel())){
            wrapper.like("contact_tel",providerVo.getContactTel());
        }
        if(Objects.nonNull(providerVo.getStatus())){
            wrapper.eq("status",providerVo.getStatus());
        }
        IPage<StockProvider>page1=providerDao.selectPage(page,wrapper);

        return new Result<>(2000,"查询",page1);
    }

    @Override
    public Result<List<StockProvider>> getAll() {
        QueryWrapper<StockProvider> wrapper =new QueryWrapper<>();
        List<StockProvider> stockProducers=providerDao.selectList(wrapper);
       return new Result(2000,"查询成功",stockProducers);
    }


}
